home *** CD-ROM | disk | FTP | other *** search
/ Freelog 46 / Freelog046.iso / Alu / Celestia / Win32LoresTex / celestia-lores-win32-1.3.0.exe / {app} / shaders / ringshadow.vp < prev    next >
Text File  |  2003-02-19  |  2KB  |  50 lines

  1. !!VP1.0
  2.  
  3. # Vertex program used for applying ring shadow textures.  Ray cast from a
  4. # point on the object in the direction of the sun (assumed to be an
  5. # infinitely distant light source here.)  Compute the intersection of
  6. # the ray with the ring plane.  Then use the distance of the intersection
  7. # point from the planet's center to compute a texture coordinate.  Vertex
  8. # programs are cool!
  9. #
  10. # c[0]..c[3] contains the concatenation of the modelview and projection
  11. # matrices.
  12. # c[16] contains the light direction in object space
  13. # c[20] contains the color
  14. # c[41] is [ inner ring radius, 1/ring width, 0, 0.5 ]
  15. # c[42] is 1 / sunDir.y
  16. # c[43] contains scaling vector [1 1-oblateness 1 0]
  17.  
  18. # Transform the vertex by the modelview matrix
  19. DP4   o[HPOS].x, c[0], v[OPOS];
  20. DP4   o[HPOS].y, c[1], v[OPOS];
  21. DP4   o[HPOS].z, c[2], v[OPOS];
  22. DP4   o[HPOS].w, c[3], v[OPOS];
  23.  
  24. # Scale by oblateness . . . off for now because it makes Saturn look
  25. # weird, even though I think it's more realistic.
  26. # MUL   R2, v[OPOS], c[43];
  27. MOV   R2, v[OPOS];
  28.  
  29. MUL   R1.x, R2.y, -c[42].x;
  30. MAX   R1.x, R1.x, c[42].w;  # Clamp to zero--don't trace both directions
  31. MAD   R0, R1.x, c[16], R2;
  32.  
  33. # Compute the distance from the center.  The s coordinate is the distance
  34. # from the center, modified by the ring width and inner radius
  35. DP3   R0.x, R0, R0;
  36. RSQ   R0.x, R0.x;
  37. RCP   R0.x, R0.x;
  38.  
  39. # Scale and bias by ring width and radius
  40. MUL   R0.x, R0.x, c[41].y;
  41. ADD   R0.x, R0.x, -c[41].x;
  42. # Now we have our s coordinate . . .
  43. MOV   o[TEX0].x, R0.x;
  44. # The t coordinate is always 0.5
  45. MOV   o[TEX0].y, c[41].w;
  46.  
  47. MOV   o[COL0], c[20];
  48.  
  49. END
  50.